<?php

class Menu extends \Phalcon\Mvc\Model
{
   public $id;
    public $vg_dm_id;
    public $vg_dm_name;
    public $dm_cha_ids;
    public $tong_sp;
    public $ngay_cn;

	public function initialize()
    {
        $this->setSource("danh_muc");
    }
   
   public function getChilds()
    {
        $result = false;

        if($this->id) {
            $frontCache = new Phalcon\Cache\Frontend\Data(array(
            "lifetime" => 172800 
            ));
            $cache = new Phalcon\Cache\Backend\File($frontCache, array(
                "cacheDir" => "../app/cache/"
            ));

            $cacheKey = "menu_$this->id.cache";
            $menu_cache    = $cache->get($cacheKey);
            if ($menu_cache === null) {

                $menu_cache = self::find("dm_cha_ids = '584,$this->vg_dm_id' OR dm_cha_ids = '575,$this->vg_dm_id'");

                // Store it in the cache
                $cache->save($cacheKey, $menu_cache);
            }

            if(count($menu_cache)) {
                $result = $menu_cache;
            }
        }

        return $result;
    }
    public function getUrl() {
        return '/priceasia/'.removeTitle($this->vg_dm_name).'-'.$this->id.'/';
    }
}